package dao;

import java.util.List;
import negocio.Feed;
import org.hibernate.Transaction;


public class DAOFeed {

    public static void guardarFeed(Feed feed) {
        Hibernate.guardarObjeto(feed);
    }

    public static List<Feed> findAll() {
        String query = "FROM negocio.Feed";
        List<Feed> resultado = Hibernate.getSession().find(query);
        Hibernate.getSession().close();
        return resultado;
    }

    public static void  delete(int id) {
        String qry = "FROM negocio.Feed WHERE id='" + id + "'";
        List Feeds = Hibernate.getSession().find(qry);
        if(Feeds != null && Feeds.size()>0)
        {
            Hibernate.getSession().delete(Feeds.get(0));
        }
        Hibernate.getSession().close();
    }

    public static boolean existe(String url) {
        String qry = "FROM negocio.Feed WHERE url='" + url + "'";
        List Feeds = Hibernate.getSession().find(qry);
        Hibernate.getSession().close();
        if (Feeds.isEmpty()) {
            return false;
        } else {
            return true;
        }
    }
}
